package com.lange.autocode.customDict;

import cn.net.autocode.core.bean.ResultT;
import cn.net.autocode.core.utils.UserThreadLocalUtils;
import cn.net.autocode.dbManager.Dao;
import cn.net.autocode.platform.customDict.CustomDict;
import cn.net.autocode.platform.customDict.CustomDictAnnotation;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import org.springframework.stereotype.Component;

@Component
@CustomDictAnnotation("sysUser")
public class SysUserDict implements CustomDict {
    private final Dao dao;

    public SysUserDict(Dao dao) {
        this.dao = dao;
    }

    @Override
    public ResultT query(JSONObject param) {
        JSONArray array = dao.queryJSONArray("select t1.username value,t1.fullname from sys_users t1,sys_organ_users t2 where t1.username=t2.username and t2.org_code=? order by t1.username", UserThreadLocalUtils.getOrgCode());
        int size = array.size();
        for(int i=0;i<size;i++){
            JSONObject json = array.getJSONObject(i);
            json.put("label",json.getString("fullname")+"【"+json.getString("value")+"】");
        }
        return ResultT.success(array);
    }
}
